<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <div class="wrapper">
      <div class="line">
        <FormPanel ref="form" :list="formList" :cols="3" :formType="type" :isSubmitBtn="false" />
        <BreakSpace label="车辆维修信息统计" :containerStyle="{ marginBottom: '10px' }"></BreakSpace>
        <FilterTable
          ref="table"
          columnsRef="jzyContactsPanel"
          height="800"
          :columns="columns"
          :fetchapi="fetchApi"
          :params="fetchParams"
          :datakey="'rows'"
          selectionType="single"
          :onRowSelectChange="rowSelectHandle"
          :onColumnsChange="columns => (this.columns = columns)"
        >
          
        </FilterTable>
        <div
          :style="{
            position: 'absolute',
            left: 0,
            bottom: 0,
            right: 0,
            zIndex: 9,
            borderTop: '1px solid #e9e9e9',
            padding: '10px 20px',
            background: '#fff',
            textAlign: 'right'
          }"
        >
          <el-button @click="closeHandler">关闭</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  // @author:@刘诗文
  import { dictionary } from '@/utils/dictMixin';
  import { authority } from '@/utils/authMixin';
  import { notifyAction, confirmAction } from '@/utils';
  import { phone, telePhone } from '@/utils/validate';
  import { getCarRepairThing } from '@/api/repair/queryStatistics/queryAccounts';
  import { getUserListSelect } from '@/api/report/repair/repairreport';
  import { searchRoleByCode } from '@/api/common/empSelect/index';
  import dictCode from '@/utils/dictCode';
  export default {
    name: 'contactsPanel',
    components: {},
    mixins: [dictionary, authority],
    props: {
      formData: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      this.selectedRow = null;
      return {
        formList: this.createFormList(),
        columns: this.createTableColumns(),
        fetchApi: getCarRepairThing,
        fetchParams: { RO_NO: this.formData.RO_NO }
      };
    },
    mounted(){
      this.initSelect();
    },
    methods: {

      async initSelect() { 
        let testDrive = { role: dictCode.SERVICE_CONSULTANT };
        let res5 = (await searchRoleByCode(testDrive)).data.map(x => ({ value: x.userId + '', text: x.employeeName })); 
        this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').editItems =  res5;
        this.columns.find(x => x.dataIndex === 'CHIEF_TECHNICIAN').editItems =  res5;
      },
      createTableColumns() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 70,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {
            title: '委托书编号',
            dataIndex: 'RO_NO',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '工时',
            dataIndex: 'STD_LABOUR_HOUR',
            sorter: true,
            filter: true,
            showOverflowTooltip: true,
            filterType: 'input'
          },
          {
            title: '维修状态',
            dataIndex: 'RO_STATUS',
            sorter: true,
            filterType: 'input',
            filter: true,
            showOverflowTooltip: true,
            filterItems: this.createDictList('8049'),
            render: props => {
              return <span>{this.createDictText(props.row.RO_STATUS, '8049')}</span>;
            }
          },
          {
            title: '牌照号',
            dataIndex: 'LICENSE',
            sorter: true,
            showOverflowTooltip: true,
            filterType: 'input',
            filter: true
          }, 
          {
            title: '服务顾问',
            dataIndex: 'SERVICE_ADVISOR',
            sorter: true,
            showOverflowTooltip: true,
            filterType: 'input',
            filter: true,
            editType: 'select',
            editItems:[]
          },
          {
            title: '项目/备件代码',
            dataIndex: 'LABOUR_PART_NO',
            sorter: true,
            showOverflowTooltip: true,
            filterType: 'input',
            filter: true
          },
          {
            title: '项目/备件名称',
            dataIndex: 'LABOUR_PART_NAME',
            sorter: true,
            showOverflowTooltip: true,
            filterType: 'input',
            filter: true
          },
          {
            title: '主修人/领料人',
            dataIndex: 'CHIEF_TECHNICIAN',
            sorter: true,
            showOverflowTooltip: true,
            filterType: 'input',
            filter: true,
            editType: 'select',
            editItems:[]
          },
          {
            title: '服务包',
            dataIndex: 'FWB',
            sorter: true,
            showOverflowTooltip: true,
            filterType: 'input',
            filter: true
          },
          {
            title: '项目属性',
            dataIndex: 'XMSX',
            sorter: true,
            showOverflowTooltip: true,
            filterType: 'input',
            filter: true
          },
          {
            title: '服务包代码',
            dataIndex: 'FWBSX',
            sorter: true,
            showOverflowTooltip: true,
            filterType: 'input',
            filter: true
          }



        ];
      },
      createFormList() {
        return [
          {
            type: 'SELECT',
            label: '*查询日期类型',
            fieldName: 'vSvcClass',
            placeholder: '请选择...',
            initialValue: '1',
            rules: [{ required: true, message: '请选择日期', trigger: 'blur' }],
            itemList: [
              { text: '送修日期', value: '1' },
              { text: '结算日期', value: '2' },
              { text: '项目派工日期', value: '3' },
              { text: '项目完工日期', value: '4' },
              { text: '审核日期', value: '5' },
              { text: '出厂日期', value: '6' }
            ]
          },
          {
            type: 'RANGE_DATE',
            label: '日期范围',
            style: { width: '250px' },
            fieldName: 'startTime|endTime'
          },
          {
            type: 'SELECT',
            label: '*委托书类别',
            fieldName: 'vSvcClass1',
            initialValue: '1',
            filterType: 'checkbox',
            filterItems: this.createDictList('9002'),
            render: props => {
              return <span>{this.createDictText(props.row.vSvcClass1,'9002')}</span>;
            }
          },
          {
            type: 'SELECT',
            label: '类别',
            fieldName: 'lb',
            initialValue: '1',
            rules: [{ required: true, message: '请选择类别', trigger: 'blur' }],
            itemList: [
              { text: '全部', value: '1' },
              { text: '项目', value: '2' },
              { text: '材料', value: '3' }
            ]
          },
          {
            type: 'INPUT',
            label: '车型',
            fieldName: 'Model',
            unitRender: () => {
              return <el-button slot="append" icon="el-icon-search" onClick={this.openPCH}></el-button>;
            },
          },
          {
            type: 'INPUT',
            label: '主修人',
            fieldName: 'ZXR',
            unitRender: () => {
              return <el-button slot="append" icon="el-icon-search" onClick={this.openPCH}></el-button>;
            },
          },
          {
            type: 'CHECKBOX',
            label: '建议维修项目',
            fieldName: 'JYWXXM',
            initialValue: 0,
          },
          {
            type: 'INPUT',
            label: '牌照号',
            fieldName: 'PZH',
            placeholder: '请输入牌照号...'
          }


        ];
      },
      changeHandle(val) {
        this.fetchParams = Object.assign({}, val);
      },
      collapseHandle() {
        this.$nextTick(() => {
          this.BaseTable.EXECUTE_RESET_HEIGHT();
        });
      },
      rowSelectHandle(rows) {
        if (!rows.length) {
          this.selectedRow = null;
        } else {
          this.selectedRow = rows[0];
        }
      },
      async removeRecordHandle() {
        try {
          await confirmAction('此操作将删除该记录, 是否继续?');
          const res = await removeContactRecord(this.selectedRow.id);
          if (res.resultCode === 200) {
            if (!res.errMsg) {
              notifyAction('删除数据成功！');
              // 执行刷新
              this.refreshHandle();
            } else {
              notifyAction(res.errMsg, 'warning');
            }
          }
        } catch (e) {}
      },
      async saveHandler() {
        try {
          // 获取表单控件的值，会执行表单校验，遵循错误前置的原则
          const [err, data] = await this.$refs.form.GET_FORM_DATA();
          if (err) return;
          const res = await saveContactInfo({ vCardId: this.formData.vCardId, vCardNo: this.formData.vCardNo, vCusName: this.formData.vCusName, ...data });
          if (res.resultCode === 200) {
            notifyAction('联系人保存成功！');
            // 执行刷新
            this.closeHandler('refresh');
          }
        } catch (e) {}
      },
      // 主页面刷新
      refreshHandle() {
        this.fetchParams = { ...this.fetchParams };
      },
      // 关闭面板
      closeHandler(type) {
        this.$emit('close', false, type);
      }
    }
  };
</script>

<style lang="less" scoped></style>
